import request from 'axios'
import config from '@/config.js'

const token = localStorage.getItem('token');

const service = request.create({
    baseURL:config.API_URL,
});

service.interceptors.request.use(
    config=>{
        if (token){
            config.headers["Authorization"]=token;
        }
        return config;
    }
)

// 响应拦截器
service.interceptors.response.use(
    response => {
        const res = response.data;
        return res;
    },

    error => {
        console.log('err' + error);
        return Promise.reject(error)
    }
)

export default service;